import axios from 'axios';
import {utilsMessage} from './utils'
const service = axios.create({
    timeout: 5000
});

service.interceptors.request.use(
    config => {
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            if(response.data.code == 0){
                return response.data;
            }else{
                utilsMessage(response.data.msg,'warning');
            }
        } else {
            Promise.reject();
        }
    },
    error => {
        utilsMessage(error,'error');
        return Promise.reject();
    }
);

export default service;
